package com.yswy.app.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yswy.app.dto.domianVo.PollingImgVo;
import com.yswy.app.service.IpPlaceService;
import com.yswy.app.service.PackageManageService;
import com.yswy.app.service.PollingImgService;
import com.yswy.domain.common.BasePojo;
import com.yswy.domain.entity.AppUser;
import com.yswy.domain.entity.PackageManage;
import com.yswy.domain.entity.PollingImg;
import com.yswy.domain.mapper.PackageBingPollingMapper;
import com.yswy.domain.mapper.PollingImgMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;


@Slf4j
@Service
public class PollingImgServiceImpl extends ServiceImpl<PollingImgMapper, PollingImg>
        implements PollingImgService {
    @Autowired
    private PackageBingPollingMapper packageBingPollingMapper ;
    @Autowired
    private PackageManageService packageManageService ;
    @Autowired
    private IpPlaceService ipPlaceService ;
    @Override
    public List<PollingImgVo> pollingImgList(Integer type , String channle , String ip ) {
        PackageManage packageManage = packageManageService.gePackageManageByChannle(channle);

        Boolean is = ipPlaceService.getIpPlaceStatus(ip);
        if (is){
            type = 100;
        }

        List<PollingImg> result = packageBingPollingMapper.getByPackageId(packageManage.getId() , type);
//        result = result.stream().sorted(Comparator.comparing(PollingImg::getImgOrder)).collect(Collectors.toList());
        List<PollingImgVo> pollingImgVos = new ArrayList<>();
        for (PollingImg p:result
        ) {
            pollingImgVos.add(new PollingImgVo(p));
        }
        return pollingImgVos;
    }
}
